//
//  RBNavigationController.m
//  RMMaterialRed
//
//  Created by XBWH on 2024/3/5.
//

#import "RBNavigationController.h"

@interface RBNavigationController ()

@end

@implementation RBNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self rb_initUI];

}
-(void)rb_initUI{
    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:RBPingFangMediumFont(16), NSForegroundColorAttributeName:RBColor(51, 51, 51)}];
    self.modalPresentationStyle = UIModalPresentationFullScreen;
    
    UINavigationBar *navigationBar = [UINavigationBar appearance];
    if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance *barAppearance = [[UINavigationBarAppearance alloc] init];
        [barAppearance setShadowImage:[[UIImage alloc] init]];
        [barAppearance setBackgroundColor:[UIColor whiteColor]];
        barAppearance.shadowColor = UIColor.clearColor;
        [barAppearance setBackgroundImage:[UIImage rb_ImageWithColor:[UIColor whiteColor]]];
        [UINavigationBar appearance].standardAppearance = barAppearance;
        [[UINavigationBar appearance] setScrollEdgeAppearance: barAppearance];
    }
    else{
        navigationBar.barTintColor = [UIColor whiteColor];
        navigationBar.shadowImage = [UIImage rb_ImageWithColor:[UIColor clearColor]];
    }
    [navigationBar setTintColor:[UIColor blackColor]];
    //设置导航栏字体样式
    [navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor], NSForegroundColorAttributeName, nil, NSShadowAttributeName, RBPingFangMediumFont(16), NSFontAttributeName, nil]];
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.childViewControllers.count > 0) { // 如果push进来的不是第一个控制器
        UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
        leftButton.frame = CGRectMake(0, 0, RBScaleWidth(44), RBScaleWidth(44));
        [leftButton setImage:[UIImage imageNamed:@"blackback"] forState:UIControlStateNormal];
        // 让按钮的内容往左边偏移10
//        leftButton.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
        [leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        // 修改导航栏左边的item
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}
- (void)back{
    [self popViewControllerAnimated:YES];
}
//关于屏幕旋转相关
- (BOOL)shouldAutorotate{
    return [self.topViewController shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return [self.topViewController preferredInterfaceOrientationForPresentation];
}

@end
